using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using QuanLy.Class;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using Common;
using WarehouseManagement.Header;

namespace WarehouseManagement.UI
{
    public partial class FormReport : Form
    {
        ConnectManager cm = new ConnectManager();
        Validator vali = new Validator();
        ReportDocument phieuDxv = new ReportDocument();
        DataSet ds;
        public DataTable tbSource, tbTongHopVan, tbTHSon;
        public string sLoaiReport;

        // Khu vuc de xuat vat tu
        public string sDonHang ,sMaDH, sTenHMSP, sMaHMSP, 
                        sKichThuoc , sSoLuong, sNguoiDeXuat,
                        sVersion, sNgayDeXuat, sNgayHoanThanh, sViTriLapDat;

        // Khu vuc Phieu mua hang
        public string sPMHID, sTenNCC, sDiaChi, sTel, sFax, sEmail, sMaPhieu;

        public FormReport(string loaiReport)
        {
            InitializeComponent();
            sLoaiReport = loaiReport;
        }

        public FormReport()
        {
            InitializeComponent();
        }

        private void FormReport_Load(object sender, EventArgs e)
        {
            switch (sLoaiReport)
            {
                case "DXVT":
                    phieuDxv.Load(@"Reports\DXVT001.rpt");
                    LoadReportDXVT(sLoaiReport);
                    break;
                case "THDXVT":
                    phieuDxv.Load(@"Reports\DXVT002.rpt");
                    LoadReportDXVT(sLoaiReport);
                    break;
                case "PhieuMuaHang":
                    phieuDxv.Load(@"Reports\DDH001.rpt");
                    LoadReportPMH();
                    break;
            }
        }

        private void addParameter(string sValue, string paraName, ref ReportDocument phieuDxv)
        {
            ParameterValues a = new ParameterValues();
            ParameterDiscreteValue b = new ParameterDiscreteValue();
            b.Value = sValue;
            a.Add(b);
            phieuDxv.DataDefinition.ParameterFields[paraName].ApplyCurrentValues(a);

        }
        public void LoadReportDXVT( String nameReport )
        {
            switch (sLoaiReport)
            {
                case "DXVT":
                    phieuDxv.Load(@"Reports\DXVT001.rpt");
                    break;
                case "THDXVT":
                    phieuDxv.Load(@"Reports\DXVT002.rpt");
                    break;
            }
            phieuDxv.SetDataSource(tbSource);

            //addParameter(sTenNCC, "DonHang", ref phieuDxv);
            addParameter(sDonHang, "DonHang", ref phieuDxv);
            addParameter(sTenHMSP, "TenSP", ref phieuDxv);
            addParameter(sMaHMSP, "MSSP", ref phieuDxv);
            //addParameter(sKichThuoc, "KichThuoc", ref phieuDxv);
            addParameter(sSoLuong, "SoLuongSP", ref phieuDxv);
            //addParameter(sNgayDeXuat, "NgayTK", ref phieuDxv);
            //addParameter(sNgayHoanThanh, "NgayHoanThien", ref phieuDxv);
            //addParameter(sNguoiDeXuat, "NguoiLap", ref phieuDxv);
            addParameter(sVersion, "Version", ref phieuDxv);

            //phieuDxv.SetDatabaseLogon("sa","12345","Giang-PC\\SQL2005","QuanLyNK");
            crystalReportViewer1.ReportSource = phieuDxv;
            crystalReportViewer1.Show();
        }


        public void LoadReportPMH()
        {
            phieuDxv.SetDataSource(tbSource);

            addParameter(sTenNCC, "TenCongTy", ref phieuDxv);
            addParameter(sDiaChi, "DiaChi", ref phieuDxv);
            addParameter(sTel, "TelNumber", ref phieuDxv);
            addParameter(sFax, "Fax", ref phieuDxv);           
            addParameter(sEmail, "Email", ref phieuDxv);
            addParameter(sMaPhieu, "MaPhieu", ref phieuDxv);
            crystalReportViewer1.ReportSource = phieuDxv;
            crystalReportViewer1.Show();
        }
    }
}